package com.houweishi.module.oaEntry.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.oaEntry.domain.OaEntry;
import com.houweishi.module.oaEntry.service.IOaEntryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入职申请Controller
 * 
 * @author yqq
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/module/oaEntry")
public class OaEntryController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(OaEntryController.class);
    @Autowired
    private IOaEntryService oaEntryService;

    /**
     * 查询入职申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaEntry:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaEntry oaEntry)
    {
        startPage();
        List<OaEntry> list = oaEntryService.selectOaEntryList(oaEntry);
        return getDataTable(list);
    }

    /**
     * 导出入职申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaEntry:export')")
    @Log(title = "入职申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaEntry oaEntry)
    {
        List<OaEntry> list = oaEntryService.selectOaEntryList(oaEntry);
        ExcelUtil<OaEntry> util = new ExcelUtil<OaEntry>(OaEntry.class);
        util.exportExcel(response, list, "入职申请数据");
    }

    /**
     * 获取入职申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaEntry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaEntryService.selectOaEntryById(id));
    }

    /**
     * 新增入职申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaEntry:add')")
    @Log(title = "入职申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaEntry oaEntry)
    {
        try {
            return oaEntryService.insertOaEntry(oaEntry);
        } catch (Exception e) {
            LOGGER.error("新增入职申请失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改入职申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaEntry:edit')")
    @Log(title = "入职申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaEntry oaEntry)
    {
        return toAjax(oaEntryService.updateOaEntry(oaEntry));
    }

    /**
     * 删除入职申请
     */
    @PreAuthorize("@ss.hasPermi('module:oaEntry:remove')")
    @Log(title = "入职申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaEntryService.deleteOaEntryByIds(ids));
    }
}
